package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.ChannelGroupAddDTO;
import org.jsola.hr.dto.ChannelGroupUpdateDTO;
import org.jsola.hr.entity.ChannelGroupDO;
import org.jsola.hr.query.ChannelGroupQuery;
import org.jsola.hr.service.IChannelGroupService;
import org.jsola.hr.vo.ChannelGroupVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 渠道分组表
 *
 * @author zhr
 */
@Component
public class ChannelGroupTestHelper extends BaseTestHelper {
    
    @Autowired
    private IChannelGroupService channelGroupService;

    /**
     * 生成add测试数据
     * @return ChannelGroupAddDTO
     */
    public ChannelGroupAddDTO getChannelGroupAddDTO(){
        ChannelGroupAddDTO channelGroupAddDTO = new ChannelGroupAddDTO();
        channelGroupAddDTO.setLevel(SafeKit.getInteger(getRandomValue("int",1)));
        channelGroupAddDTO.setName(getRandomValue("varchar",30));
        channelGroupAddDTO.setDescribe(getRandomValue("varchar",150));
        return channelGroupAddDTO;
    }


    /**
     * 生成update测试数据
     * @return ChannelGroupUpdateDTO
     */
    public ChannelGroupUpdateDTO getChannelGroupUpdateDTO(ChannelGroupVO channelGroupVO){
        return channelGroupService.selectDOById(channelGroupVO.getId(), SITE_ID).to(ChannelGroupUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return ChannelGroupQuery
     */
    public ChannelGroupQuery getChannelGroupQuery() {
        ChannelGroupQuery channelGroupQuery = new ChannelGroupQuery();
        List<ChannelGroupDO> channelGroupDOList = channelGroupService.list(new ChannelGroupDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(channelGroupDOList)) {
            ChannelGroupDO channelGroupDO = channelGroupDOList.get(0);
            channelGroupQuery = channelGroupDO.to(ChannelGroupQuery.class);
        }
        return channelGroupQuery;
    }

    /**
     * 保存示例
     * @return ChannelGroupVO
     */
    public ChannelGroupVO saveChannelGroupExample(){
        ChannelGroupAddDTO addDTO = this.getChannelGroupAddDTO();
        ChannelGroupVO channelGroupVO = channelGroupService.save(addDTO,buildTokenUser());
        return channelGroupVO;
    }


}

